---
import type { CollectionEntry } from "astro:content";
import Layout from "@layouts/Layout.astro";
import Main from "@layouts/Main.astro";
import Header from "@components/Header.astro";
import Footer from "@components/Footer.astro";
import Pagination from "@components/Pagination.astro";
import Card from "@components/Card";
import { SITE } from "@config";

export interface Props {
  currentPage: number;
  totalPages: number;
  paginatedPosts: CollectionEntry<"blog">[];
}

const { currentPage, totalPages, paginatedPosts } = Astro.props;
---

<Layout title={`Posts | ${SITE.title}`}>
  <Header activeNav="posts" />
  <Main pageTitle="Posts" pageDesc="All the articles I've posted.">
    <ul>
      {
        paginatedPosts.map(({ data, slug }) => (
          <Card href={`/posts/${slug}/`} frontmatter={data} />
        ))
      }
    </ul>
  </Main>

  <Pagination
    {currentPage}
    {totalPages}
    prevUrl={`/posts${currentPage - 1 !== 1 ? "/" + (currentPage - 1) : ""}/`}
    nextUrl={`/posts/${currentPage + 1}/`}
  />

  <Footer noMarginTop={totalPages > 1} />
</Layout>
